<?php namespace Home\Controller; 

use Hdphp\Controller\Controller;



//测试控制器
class ContentController extends Controller{




	//构造函数
	public function __init()
	{
	
		
	}
	
    //动作
    public function index(){
//  	p($_SESSION);die;
//  	var_dump($_GET);die;
		$gid = Q('get.gid',0,'intval');
//		分配到前台的隐藏框里面，ajax要用
		View::with('gid',$gid);
//		获得该产品的属性
		$goodsData = Db::table('snshop_goods') 
		-> join('snshop_detail','gid','=','snshop_goods_gid')
		-> where('gid',$gid) 
		-> first();
//		var_dump($goodsData);die;

//		获取大小中图片路径，输出到前台
		$small = $goodsData['small'];
//		组合数组
		$smallArr = explode(";", $small);
		
		$medium = $goodsData['medium'];
//		组合数组
		$mediumArr = explode(";", $medium);
		View::with('mediumArr',$mediumArr);
		
		$big = $goodsData['big'];
//		组合数组
		$bigArr = explode(";", $big);
//		var_dump($bigArr);die;
		View::with('bigArr',$bigArr);
		
//		大小图路径
		$dirN = "Upload/Content/16/07/pro-z/";
		foreach($smallArr as $k => $v){
			$smallArr[$k] = $dirN.$v;
		}
//		var_dump($smallArr);die;
//		分配数据
		View::with('smallArr',$smallArr);


//		分配前台
		View::with('goodsData',$goodsData);
//		查询当前商品的商品属性
		$goodsAttrData = Db::table('snshop_goods_attr ga') 
		-> join('snshop_type_attr ta','ga.taid','=','ta.taid')
		-> where('snshop_goods_gid',$gid) 
		-> get();
//		var_dump($goodsAttrData);die;
		
		
//		属性
		$shuxingData = Db::table('snshop_goods_attr ga') 
		-> join('snshop_type_attr ta','ga.taid','=','ta.taid')
		-> where('snshop_goods_gid',$gid) 
		-> where('class',0)
		-> get();
//		var_dump($shuxingData);
		
//		规格
		$guigeData = Db::table('snshop_goods_attr ga') 
		-> join('snshop_type_attr ta','ga.taid','=','ta.taid')
		-> where('snshop_goods_gid',$gid) 
		-> where('class',1)
		-> orderBy('ga.gtid')
		-> groupBy('ta.taid')
		-> get();
//		p($guigeData);die;
		foreach($guigeData as $k => $v){
			$guigeData[$k]['sonData'] = Db::table('snshop_goods_attr ga') 
				-> join('snshop_type_attr ta','ga.taid','=','ta.taid')
				-> where('snshop_goods_gid',$gid) 
				-> where('class',1)
				-> where('ta.taid',$v['taid'])
				-> get();
		}
//		var_dump($guigeData);die;
		View::with('guigeData',$guigeData);
		
		
    	View::make();
    }


	public function getPrice(){
//		echo $_POST['num'];
		$gid = $_POST['gid'];
		$num = $_POST['num'];		
//		去除前台组合的字符串最后一个逗号
		$num = rtrim($num,",");
//		将传进来的combine组合成数组，排序，再变回字符串
		$num = explode(",", $num);
		sort($num);
		$num = implode(",", $num);
//		echo $num;
//		echo $_POST['gid'];
//		$goodsListModel = new \Common\Model\GoodsList;
//		$goodsListData = $goodsListModel -> where('snshop_goods_gid',$gid) -> get();
////		p($goodsListData);die;
//		foreach($goodsListData as $k => $v){
//			if($v['combine'] == $num){
//				echo $v['inventory'];
//			}
//		}
//		die();
		$inventory = Db::table('snshop_goods_list') -> where('combine',$num) -> pluck('inventory');
		$inventoryArr = array('inventory' => $inventory);
		View::ajax($inventoryArr);
		
	}


}
